package com.zmc.member.controller;

import com.zmc.common.annotation.PreventRepeatSubmit;
import com.zmc.common.enums.RequestSourceEnum;
import com.zmc.member.infrastructure.bean.vo.ReceiveAddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zmc.member.infrastructure.service.MemberReceiveAddressService;
import com.zmc.common.utils.R;



/**
 * 会员收货地址
 *
 * @author zmc
 * @email 
 * @date 2024-10-09 14:56:33
 */
@RestController
@RequestMapping("/address")
public class MemberReceiveAddressController {

    @Autowired
    private MemberReceiveAddressService memberReceiveAddressService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public R list(){
        return R.ok(memberReceiveAddressService.listReceiveAddress());
    }


    /**
     * 保存
     */
    @PostMapping("/add")
    @PreventRepeatSubmit(lockByPerson = true, source = RequestSourceEnum.WEB)
    public R save(@RequestBody ReceiveAddressVo receiveAddressVo){
        memberReceiveAddressService.saveReceiveAddress(receiveAddressVo);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @PreventRepeatSubmit(lockByPerson = true, source = RequestSourceEnum.WEB)
    public R update(@RequestBody ReceiveAddressVo receiveAddressVo){
		memberReceiveAddressService.updateReceiveAddress(receiveAddressVo);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody ReceiveAddressVo receiveAddressVo){
		memberReceiveAddressService.removeById(receiveAddressVo.getId());
        return R.ok();
    }

    /**
     * 获取信息
     */
    @GetMapping("/info/{id}")
    public R receiveAddressInfo(@PathVariable("id") Long id){
        return R.ok(memberReceiveAddressService.getById(id));
    }

}
